<?php
/*
** Module name : Tab Facebook Comment
** Ver : 0.1
** Author : Proglamour
** e-mail : jr.rahmat@gmail.com
** Release date : 7 April 2011
** Licence : free
*/

class tabfbcomment extends Module
{
    private $_html = '';
    private $_postErrors = array();

    function __construct()
    {
        $this->name = 'tabfbcomment';
        $this->tab = 'All about facebook';
        $this->version = '0.1';

        parent::__construct();

        $this->displayName = $this->l('Tab Facebook Comment');
        $this->description = $this->l('Add a facebook comment on product page tab');
    }

    function install()
    {
		if (!parent::install())
			return false;
		if (!$this->registerHook('productTab') OR !$this->registerHook('ProductTabContent'))
			return false;
		return true;
    }

	public function displayForm()
	{

  	$output .=
		'<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
			<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
				<label>'.$this->l('Your Facebook App ID').'</label>
				<div class="margin-form">
					<input type="text" size="10" name="appNbr" value="'.Tools::getValue('appNbr', Configuration::get('FACEBOOK_APPID')).'" />
				</div>				
				<center><input type="submit" name="submitFbAppID" value="'.$this->l('Save').'" class="button" /></center>
			</fieldset>
		</form>';
		return $output;
	}
	
	function getContent()
	{
		$output .= '<h2>'.$this->l('Facebook Comment settings').'</h2>';
		if (Tools::isSubmit('submitFbAppID'))
		{
			//update facebook app id
			if (!$appNbr = Tools::getValue('appNbr') OR empty($appNbr))
				$output .= '<div class="alert error">'.$this->l('You should fill facebook app id field').'</div>';
			else
			{
				Configuration::updateValue('FACEBOOK_APPID', ($appNbr));
				$output .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('Confirmation').'" />'.$this->l('Settings updated').'</div>';
			}
		}
		return $output.$this->displayForm();
	}
    
	public function hookProductTab($params)
    {
		global $smarty;
		global $cookie;

		$smarty->assign(null);
		return ($this->display(__FILE__, '/tabfbcomment.tpl'));
		
	}

    public function hookProductTabContent($params)
    {
		global $smarty;
		
		$id_appFb = Configuration::get('FACEBOOK_APPID');
	    if ($_DEBUG == 1) {
        echo 'Id APP Fb: '.$id_appFb.'</br>';
		}
		$smarty->assign('id_appFb', $id_appFb);
		return ($this->display(__FILE__, '/contentfbcomment.tpl'));
	}
}

?>
